package Server_Netty;

import Server_Netty.TCP.TCPServer;
import Server_Netty.UDP.UDPServer;

public class Start_Server_Thread extends Thread{
    int Role_Id;
    int Role_port;
    String Role_ConnectWay;

    private String localAddress;
    public Start_Server_Thread(String Connect_Way, int RoleID, String local_address, int port) {
        Role_Id=RoleID;
        Role_port=port;
        Role_ConnectWay=Connect_Way;

        localAddress = local_address;
    }

    //2):在A类中覆盖Thread类中的run方法.
    public void run() {
        if (Role_ConnectWay.equalsIgnoreCase("TCP"))
        {
            TCPServer tcp = new TCPServer(Role_Id);
            try {
                Thread.sleep(3000);
                //System.out.println(tcp);
                Main_Send_Receive_Manager.RoleID_TCPServer.put(Role_Id, tcp);

                tcp.bind(localAddress, Role_port);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        else if (Role_ConnectWay.equalsIgnoreCase("UDP"))
        {
            UDPServer udp=new UDPServer(Role_Id,Role_port);
            try {
                Thread.sleep(3000);
                Main_Send_Receive_Manager.RoleID_UDPServer.put(Role_Id, udp);
                udp.bind(localAddress, Role_port);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        else {
            Main_Send_Receive_Manager.LOGGER.info("本系统暂时不支持该连接方式");
        }

    }
}
